package com.lsk.netdisk.commons.authz.aspect;

import com.lsk.netdisk.common.redis.core.RedisComponent;
import com.lsk.netdisk.commons.authz.properties.AuthzProperties;
import com.lsk.netdisk.commons.authz.utils.AOPUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class GatewayAspect {
	@Autowired
	private AuthzProperties authzProperties;
	@Autowired
	private RedisComponent redisComponent;

	@Pointcut("@annotation(com.lsk.netdisk.commons.authz.annotation.Gateway)")
	public void pointcut(){}

	@Around("pointcut()")
	public Object around(ProceedingJoinPoint pjp) throws Throwable{
		Object result = null;
		try{
			if(authzProperties.getStandalone()){
				String code = AOPUtil.getParam(pjp,"gatewayCode",String.class);
			}else{
				result = pjp.proceed();
			}
		}catch (Throwable t){
			log.error("Error: ",t);
			throw t;
		}
		return result;
	}
}
